-
-
Notifications
You must be signed in to change notification settings - Fork 454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notify when Manager.from_queryset happens inside model class body #824
Notify when Manager.from_queryset happens inside model class body #824
Conversation
05bba51
to
9959813
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you!
- A warning will be emitted whenever `Manager.from_queryset` happens inside of a model class body
9959813
to
428c34d
Compare
I've removed the setting so that the new check is always enabled |
Seems like some related manager issues popped up when enforcing the check. Gonna try to dig in and see if I can resolve them |
Feel free to ask any questions! 👍 |
default_manager = related_model_info.get("_default_manager") | ||
if not default_manager: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed from objects
to _default_manager
with https://docs.djangoproject.com/en/dev/topics/db/queries/#using-a-custom-reverse-manager as justification ("By default the RelatedManager used for reverse relations is a subclass of the default manager for that model.")
@@ -360,7 +358,7 @@ def run_with_model_cls(self, model_cls: Type[Model]) -> None: | |||
def try_generate_related_manager( | |||
self, related_model_cls: Type[Model], related_model_info: TypeInfo | |||
) -> Optional[Instance]: | |||
manager = related_model_cls._meta.managers_map["objects"] | |||
manager = related_model_cls._meta.managers_map["_default_manager"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed from objects
to _default_manager
with https://docs.djangoproject.com/en/dev/topics/db/queries/#using-a-custom-reverse-manager as justification ("By default the RelatedManager used for reverse relations is a subclass of the default manager for that model.")
A default manager on a model should always exist, eventually. Although, we extend to look through dynamically generated managers on each iteration instead of deferring until the final iteration.
8fa5f52
to
2ee2995
Compare
Alright, I think the related manager issues are resolved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Whenever
Manager.from_queryset
happens inside of a model class body, an error will be displayede.g. Doing
Yields:
Note: I've also included a refactoring commit for config parsing, that hopefully will make it less of a hassle to introduce new settings in the future.
Related issues
Refs #738